﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class adm_vlg_gigDetails : System.Web.UI.Page
{
    VLGDataContext _db8 = new VLGDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["action"] != null && Request.QueryString["action"].ToUpper().Equals("DELETE"))
        {
            try
            {
                var idGig = Convert.ToInt32(Request.QueryString["id"]);
                var gig = _db8.Gigs.Select(p => p).Where(p => p.idGig == idGig).FirstOrDefault();
                var comment = _db8.GigComments.Where(c => c.idGig == idGig);
                var order = _db8.Orders.Where(o => o.idGig == idGig);
                foreach (var item in order)
                {
                    var gigState = _db8.GigStates.Where(s => s.idDH==item.idDH);
                    _db8.GigStates.DeleteAllOnSubmit(gigState);

                }
                _db8.Orders.DeleteAllOnSubmit(order);
                _db8.GigComments.DeleteAllOnSubmit(comment);
                _db8.Gigs.DeleteOnSubmit(gig);
                _db8.SubmitChanges();
            }
            catch { }
            Response.Redirect("gig.aspx");
        }
        FillData();
    }
    public void FillData()
    {
        try
        {
            int gigId = Int32.Parse(Request.QueryString["id"]);
            Gig gig = _db8.Gigs.Single(x => x.idGig == gigId);
            lblGioiThieu.Text = gig.TuGioiThieu;
            hdDuyet.Value = gig.Duyet != null ? gig.Duyet.ToString().ToUpper().Equals("TRUE") ? "0" : "1" : "-1";
        }
        catch
        {

        }

    }
    protected void butt_save_Click(object sender, EventArgs e)
    {
        var gig = _db8.Gigs.SingleOrDefault(x => x.idGig == Convert.ToInt32(Request.QueryString["id"]));
        int value = Convert.ToInt32(ddlDuyet.Value);
        if (value == 0)
        {
            gig.Duyet = true;
            gig.TrangThai = 3;
        }
        else if (value == 1)
        {
            gig.Duyet = true;
            gig.TrangThai = 1;
        }
        _db8.SubmitChanges();
        Response.Redirect("gig.aspx");


    }
}